package com.evil.enterprise.controller;

import com.evil.application.api.RemoteApplicationPackageService;
import com.evil.application.pojo.dto.ReorderApplicationReqDTO;
import com.evil.application.pojo.dto.pack.*;
import com.evil.common.core.entity.R;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.constraints.NotEmpty;
import java.util.List;

/**
 * 应用包接口
 *
 * @author liyang
 * @date 2022-08-08 00:00
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/application/package")
public class ApplicationPackageController {

    private final RemoteApplicationPackageService remoteApplicationPackageService;

    /**
     * 获取应用包基础信息
     *
     * @param packageId packageId
     * @return R
     */
    @PostMapping("/base-info")
    public R<PackageBaseInfoRespDTO> packageBaseInfo(@RequestParam("packageId") Long packageId) {
        return R.success(remoteApplicationPackageService.packageBaseInfo(packageId));
    }

    /**
     * 获取应用包信息
     *
     * @param packageAppListInfoReqDTO packageAppListInfoReqDTO
     * @return R
     */
    @PostMapping("/info")
    public R<PackageInfoRespDTO> packageInfo(@Validated @RequestBody PackageAppListInfoReqDTO packageAppListInfoReqDTO) {
        return R.success(remoteApplicationPackageService.packageInfo(packageAppListInfoReqDTO));
    }

    /**
     * 获取应用包列表
     *
     * @return R
     */
    @PostMapping("/list")
    public R<List<PackageRespDTO>> packageList(@Validated @RequestBody PackageListReqDTO packageListReqDTO) {
        packageListReqDTO.setEnterpriseId(null);
        return R.success(remoteApplicationPackageService.packageList(packageListReqDTO));
    }

    /**
     * 新增应用包
     *
     * @param addPackageReqDTO addPackageReqDTO
     * @return R
     */
    @PostMapping("/add")
    public R<?> addPackage(@Validated @RequestBody AddPackageReqDTO addPackageReqDTO) {
        addPackageReqDTO.setEnterpriseId(null);
        remoteApplicationPackageService.addPackage(addPackageReqDTO);
        return R.success();
    }

    /**
     * 重新排序应用包
     *
     * @param packageIds packageIds
     * @return R
     */
    @PostMapping("/reorder")
    public R<?> reorderPackage(@NotEmpty(message = "关键参数为空") List<Long> packageIds) {
        remoteApplicationPackageService.reorderPackage(packageIds);
        return R.success();
    }

    /**
     * 编辑应用包
     *
     * @param modifyPackageReqDTO modifyPackageReqDTO
     * @return R
     */
    @PostMapping("/modify")
    public R<?> modifyPackage(@Validated @RequestBody ModifyPackageReqDTO modifyPackageReqDTO) {
        remoteApplicationPackageService.modifyPackage(modifyPackageReqDTO);
        return R.success();
    }

    /**
     * 删除应用包
     *
     * @param deletePackageReqDTO deletePackageReqDTO
     * @return R
     */
    @PostMapping("/delete")
    public R<?> deletePackage(@Validated @RequestBody DeletePackageReqDTO deletePackageReqDTO) {
        remoteApplicationPackageService.deletePackage(deletePackageReqDTO);
        return R.success();
    }

    /**
     * 重新排序应用包应用
     *
     * @param reorderApplicationReqDTO reorderApplicationReqDTO
     * @return R
     */
    @PostMapping("/item/reorder")
    public R<?> reorderApplication(@Validated @RequestBody ReorderApplicationReqDTO reorderApplicationReqDTO) {
        remoteApplicationPackageService.reorderApplication(reorderApplicationReqDTO);
        return R.success();
    }
}
